package com.shanling.shanlingcontroller.base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.shanling.shanlingcontroller.persenter.BasePersenter;
import com.shanling.shanlingcontroller.ui.BaseView;


/**
 * Created by sinrow on 2019/2/12 0012.
 */

public abstract class BaseMVPFragment<T extends BasePersenter> extends BaseLazyFragment implements BaseView {

    protected T mPresenter;

    protected abstract T createPresenter();


    @Nullable
    @Override
    @SuppressWarnings("unchecked")
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        if (mPresenter == null) {
            mPresenter = createPresenter();
        }
        mPresenter.attachView(this);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.detachView();
    }
}
